import Vue from 'vue'
import axios  from 'axios' 

axios.defaults.baseURL="http://db.hocent.cn/api"
Vue.prototype.$ajax = axios;
axios.defaults.withCredentials = true;
axios.defaults.crossDomain = true;
 //axios.defaults.headers = {
 // "Content-Type": "application/x-www-form-urlencoded"
 // }
axios.interceptors.request.use(
    config => {
      if (localStorage.getItem('Auth')) {
        config.headers.Authorization = localStorage.getItem('Auth');
      }
   
      return config;
    },
    error => {
      return Promise.reject(error);
    });

    axios.interceptors.response.use(
      function(res) {
        if(res.status==401){
          localStorage.removeItem('Authorization');
          localStorage.removeItem('username');
          localStorage.removeItem('Auth');
           
           this.$router.push('/login');
        }
        // 如果账号在其他地方登陆
       
        return res;
      },
      function(error) {
        return Promise.reject(error);
      }
    );